"""Build versioned object store tests"""


def scons():
    """Execute build"""
    Import('denv', 'utest_utils', 'conf_dir', 'cmd_parser')

    # build and export objects used by other unit tests
    senv = denv.Clone()
    senv.Append(CPPPATH=[Dir('..').srcnode()])
    senv.Append(OBJPREFIX="vts_")
    vts_src = ['vts_dtx.c', 'vts_io.c', 'vts_common.c', '../../object/srv_csum.c',
               '../../object/srv_io_map.c']
    vts_objs = senv.StaticObject(vts_src)
    Export('vts_objs')

    libraries = ['vos', 'bio', 'abt', 'pthread', 'daos_common_pmem',
                 'daos_tests', 'gurt', 'uuid', 'pthread',
                 'pmemobj', 'cmocka', 'gomp']

    tenv = denv.Clone()
    tenv.Append(CPPPATH=[Dir('..').srcnode()])

    tenv.require('isal', 'argobots')

    # Add runtime paths for daos libraries
    tenv.AppendUnique(RPATH_FULL=['$PREFIX/lib64/daos_srv'])
    tenv.Append(OBJPREFIX="b_")

    vos_test_src = ['vos_tests.c', vts_objs, 'vts_pool.c', 'vts_container.c',
                    'vts_aggregate.c', 'vts_gc.c', 'vts_checksum.c', 'vts_ilog.c',
                    'vts_array.c', 'vts_pm.c', 'vts_ts.c', 'vts_mvcc.c',
                    'vos_cmd.c', 'vts_wal.c']
    vos_tests = tenv.d_program('vos_tests', vos_test_src, LIBS=libraries)
    tenv.AppendUnique(CPPPATH=[Dir('../../common/tests').srcnode()])
    evt_ctl = tenv.d_program('evt_ctl', ['evt_ctl.c', utest_utils, cmd_parser], LIBS=libraries)

    tenv.Install('$PREFIX/bin/', [vos_tests, evt_ctl])
    tenv.Install(conf_dir, ['vos_size_input.yaml'])

    unit_env = tenv.Clone()
    unit_env.AppendUnique(RPATH_FULL=['$PREFIX/lib64/daos_srv'])

    libraries = ['daos_common_pmem', 'daos_tests', 'gurt', 'cart', 'cmocka',
                 'vos', 'uuid', 'pmem', 'pmemobj', 'bio', 'pthread', 'abt']
    unit_env.d_test_program('pool_scrubbing_tests', ['pool_scrubbing_tests.c',
                                                     '../vos_pool_scrub.c'],
                            LIBS=libraries)

    tenv = denv.Clone()
    tenv.AppendUnique(RPATH_FULL=['$PREFIX/lib64/daos_srv'])
    tenv.Append(CPPDEFINES={'VOS_STANDALONE': '1'})

    libraries = ['uuid', 'bio', 'gurt', 'cmocka', 'daos_common_pmem', 'daos_tests', 'vos', 'abt']

    tenv.require('spdk')
    bio_ut_src = ['bio_ut.c', 'wal_ut.c']
    bio_ut = tenv.d_test_program('bio_ut', bio_ut_src, LIBS=libraries)
    tenv.Install('$PREFIX/bin/', bio_ut)


if __name__ == "SCons.Script":
    scons()
